home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8898 < prev    next >
Encoding:
Text File  |  1996-08-05  |  3.0 KB  |  82 lines

  1. Path: dildog.lgc.com!usenet
  2. From: Glenn Carr <gcarr@tulsa.lgc.com>
  3. Newsgroups: gnu.gcc.help,comp.lang.c
  4. Subject: gcc 2.7.2 warning: left-hand operand of comma expression has no effect
  5. Date: Wed, 06 Mar 1996 13:39:53 -0600
  6. Organization: Landmark Graphics
  7. Message-ID: <313DEA09.237C@tulsa.lgc.com>
  8. NNTP-Posting-Host: 134.132.131.47
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 2.0 (X11; I; AIX 1)
  13. CC: "Christopher A. Smith" <casmith@clark.net>
  14.  
  15. We've just moved from gcc 2.6.3 to 2.7.2 and we're receiving the following new
  16. warnings (when -Wall is specified)....
  17.  
  18. warning: left-hand operand of comma expression has no effect
  19.  
  20.  
  21. When this section of code is encountered in our source files...
  22.  
  23. static char    *rcsid = "$Id: cfgopen.c,v 1.4 1995/12/11 16:04:35 gcarr Exp $";
  24. #if __GNUC__ == 2
  25. #define USE(var) static void * use_##var = (&use_##var, (void *) &var)
  26. USE(rcsid);
  27. #endif
  28.  
  29. (This puts the version stamp of each source file in the executable so that we
  30. can use rcs indent to read the stamps from the exe file if there is a question about
  31. which source was used to build.  The USE macro, fakes gcc into thinking (or used to)
  32. that 'rcsid' is used when in fact it is not, so that gcc wouldn't complain about
  33. unused variables if -Wunused is set.)
  34.  
  35. We also have another frequent occurrence of this problem.  We have defined a 'Dbg'
  36. macro as follows...
  37.  
  38. void            _DbgLog1(char *pszFile, int nLine, char *pszTimeFmt);
  39. void            _DbgLog2(char *pszFmt,...);
  40. #ifdef DEBUG
  41. #define Dbg    _DbgLog1(__FILE__, __LINE__, DBGLOG_TIMEFMT), _DbgLog2
  42. #else
  43. #define Dbg    (void)
  44. #endif /* DEBUG */
  45.  
  46. We use this for logging debug/trace to stdout if DEBUG is defined.  'Dbg' is defined
  47. to as two functions in order to print the __FILE__ and __LINE__ along with any printf
  48. style parameters without explicitly including the __FILE__ and __LINE__ in the Dbg
  49. call.
  50.  
  51. Dbg("The value of x is %d\n", x);
  52.  
  53. ...which outputs something like this...
  54.  
  55. [file.c,897] The value of x is 32
  56.  
  57.  
  58. Anyway, can this warning be turned off without turning off -Wall or -Wunused (warns
  59. about unused variables and labels)?  I found this section of code in the gcc source...
  60.  
  61. ...
  62.  
  63.       /* The left-hand operand of a comma expression is like an expression
  64.          statement: with -W or -Wunused, we should warn if it doesn't have
  65.          any side-effects, unless it was explicitly cast to (void).  */
  66.       if ((extra_warnings || warn_unused)
  67.            && ! (TREE_CODE (TREE_VALUE (list)) == CONVERT_EXPR
  68.                 && TREE_TYPE (TREE_VALUE (list)) == void_type_node))
  69.         warning ("left-hand operand of comma expression has no effect");
  70.  
  71. ...
  72.  
  73. How do I or can I "explicitly cast to (void)" the return value(s) of these
  74. comma-separated expressions to get rid of these warnings?  Or is there another way to
  75. get rid of these warnings without getting rid of -Wunused?   I would prefer to work
  76. around these two specific problems and continue to get the warning for other cases.
  77.  
  78. --
  79. Glenn Carr
  80. gcarr@lgc.com
  81. Landmark Graphics
  82.